import pymysql

# 之连接一次数据库，将所有的信息存放进去
class MysqlHelper(object):
    def __init__(self):
        self.conn = pymysql.connect(host='192.168.1.14',port=3306,user='root',password='curry98519',database='spider_project',charset='utf8')
        self.cursor = self.conn.cursor()

    # 一个sql语句，一个data数据
    def execute_modify_sql(self,sql,data):
        self.cursor.execute(sql,data)
        self.conn.commit()

    def __del__(self):
        self.cursor.close()
        self.conn.close()

if __name__ == '__main__':
    helper = MysqlHelper()
    sql = 'INSERT INTO pachong.xueqiu VALUES(null,%s,%s,%s)'
    data = (123,'ggg','aaa')
    helper.execute_modify_sql(sql,data)
